
/************************************************************************************
*  Copyright (c), 2006-2007, huntersun All rights reserved.
*
* File name: Uart.c
* Project  : 
* Processor:
* Compiler : 
* 
* Author :ldj
* Version: 
* Date   : 
* Modification: 
* 
* Description: 
*		driver for uart0&uart1 of C8051F380.note that the driver for uart 0 is ok,the driver for uart1 has no tested,and may be unusable.
*
* Others: none;
*
* History:
*
*************************************************************************************/
#include "C8051F380_defs.h"
//#include "C8051F380_init_device.h" 

#include "hw_timer.h"


/******************************************************
*modifed by lidianjun 2014,5,28 for make the timer more accurate
*******************************************************/
void Timer0_InitMs()
{
	unsigned int count;
    
	CKCON &= 0xF8;

	TMOD &= ~0x0f;
	TMOD|=0x01;

	count = 65536 - 40000 + 8;			//10ms

	TH0 = (count>>8)&0x00ff;
	TL0 = count&0x00ff;

	ET0 = 1;  /*enable intr*/ 
	TR0 = 1;
}

void Timer0_Init500us()
{
	unsigned int count;
    
	CKCON &= 0xF8;

	TMOD &= ~0x0f;
	TMOD|=0x01;

	count = 65536 - 1800 + 8;			/*450us*/

	TH0 = (count>>8)&0x00ff;
	TL0 = count&0x00ff;

	ET0 = 1;  /*enable intr*/
	TR0 = 1;

}

void TImer0Disable(void)
{
	TR0 = 0;
	TH0 = 0;
	TL0 = 0;
}



